# Maintainer: Tim Meusel <tim@bastelfreak.de>

_gemname='bcrypt_pbkdf'
pkgname="ruby-${_gemname}"
pkgver=1.1.0
pkgrel=3
pkgdesc="OpenBSD's bcrypt_pdkfd (a variant of PBKDF2 with bcrypt-based PRF)"
arch=('loong64' 'x86_64')
url='https://github.com/net-ssh/bcrypt_pbkdf-ruby'
license=('MIT')
depends=('ruby')
makedepends=('ruby-rake' 'ruby-bundler' 'ruby-rdoc' 'ruby-rake-compiler')
checkdepends=('ruby-minitest')
options=('!emptydirs')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/v${pkgver}.tar.gz")
sha512sums=('d7a21ff439b2d023597f1cd45e16b9072f4747fa9498dbcb1920a615dcd09ac020ebbe2a99275042d7bf87a4db207b8329a3c7ef2a95405ad0491d0b8afb6d02')
provides=('bcrypt_pbkdf_ext.so')
prepare() {
  cd "${srcdir}/${_gemname}-ruby-${pkgver}"

  sed -E 's|~>|>=|g' --in-place "${_gemname}.gemspec"
  sed --in-place 's|git ls-files|find|' "${_gemname}.gemspec"
  sed --in-place '/bundler/d' Rakefile
  sed --in-place '/rake-compiler-dock/d' bcrypt_pbkdf.gemspec
  sed --in-place '/has_rdoc/d' bcrypt_pbkdf.gemspec
}

build() {
  cd "${srcdir}/${_gemname}-ruby-${pkgver}"
  rake compile
  rake gem
}

check() {
  cd "${srcdir}/${_gemname}-ruby-${pkgver}"
  rake test
}

package() {
  cd "${srcdir}/${_gemname}-ruby-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --ignore-dependencies --no-user-install --install-dir "${pkgdir}${_gemdir}" --bindir "${pkgdir}/usr/bin" "pkg/${_gemname}-${pkgver}.gem"
  install -Dm 644 README.md CHANGELOG.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  rm -rf ${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/{ext,tmp}
  rm -rf "${pkgdir}/${_gemdir}/cache"
  rm -rf ${pkgdir}/${_gemdir}/extensions/*/*/${_gemname}-${pkgver}/{mkmf.log,gem_make.out}
  rm -rf "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext"
}

# vim: ts=2 sw=2 et:
